Skip to content

Conversation

@yashuatla
Copy link
Owner

@yashuatla yashuatla commented Jun 27, 2025

PR Summary

Code Modernization and Introduction of Actor Model Implementation

Overview

This PR introduces a new Actor Model implementation through the ActorSystem class while modernizing existing code through various refactoring techniques including Java language feature updates, test improvements, and code style enhancements.

Change Types

Type Description
Feature Introduction of ActorSystem class for actor model implementation
Refactor Code modernization using newer Java features and improved test patterns
Style Access modifier adjustments and code style improvements

Affected Modules

Module / File Change Description
src/main/java/com/iluwatar/actormodel/ActorSystem.java New class implementing actor model pattern with actor management functionality
src/main/java/com/iluwatar/servicestub/RealSentimentAnalysisServer.java Refactored to use switch expression instead of ternary operator
src/test/java/com/iluwatar/monolithic/MonolithicAppTest.java Simplified lambda expression in test method
src/test/java/com/iluwatar/publish/subscribe/LoggerExtension.java Updated to use modern Java stream API (toList() instead of collect)
src/test/java/com/iluwatar/publish/subscribe/model/MessageTest.java Changed access modifiers to package-private
src/test/java/com/iluwatar/sessionfacade/AppTest.java Changed class visibility to package-private
src/test/java/com/iluwatar/sessionfacade/PaymentServiceTest.java Refactored to use parameterized tests with @CsvSource
src/test/java/com/iluwatar/table/inheritance/AppTest.java Added package declaration and removed unnecessary import
src/test/java/com/iluwatar/table/inheritance/VehicleDatabaseTest.java Changed access modifier and added package declaration

dependabot bot and others added 15 commits April 15, 2025 18:10
…ar#3254)

Bumps [com.diffplug.spotless:spotless-maven-plugin](https://github.com/diffplug/spotless) from 2.44.3 to 2.44.4.
- [Release notes](https://github.com/diffplug/spotless/releases)
- [Changelog](https://github.com/diffplug/spotless/blob/main/CHANGES.md)
- [Commits](diffplug/spotless@maven/2.44.3...maven/2.44.4)

---
updated-dependencies:
- dependency-name: com.diffplug.spotless:spotless-maven-plugin
  dependency-version: 2.44.4
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* feat: Implement Actor Model pattern iluwatar#3232

* feat: Implement Actor Model pattern iluwatar#3232

* feat: update Actor Model implementation with multi-actor logic iluwatar#3251

* feat: update Actor Model implementation with multi-actor logic and loose coupling  iluwatar#3251

* test: add unit test for actor model iluwatar#3251

* test: add test for App.java to increase coverage

* docs: add complete README for Actor Model pattern also implemented changes iluwatar#3251
* docs: update README.md [skip ci]

* docs: update .all-contributorsrc [skip ci]

---------

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
* docs: update README.md [skip ci]

* docs: update .all-contributorsrc [skip ci]

---------

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
Bumps [org.springframework:spring-web](https://github.com/spring-projects/spring-framework) from 7.0.0-M3 to 7.0.0-M4.
- [Release notes](https://github.com/spring-projects/spring-framework/releases)
- [Commits](spring-projects/spring-framework@v7.0.0-M3...v7.0.0-M4)

---
updated-dependencies:
- dependency-name: org.springframework:spring-web
  dependency-version: 7.0.0-M4
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
…luwatar#3261)

Bumps [org.sonarsource.scanner.maven:sonar-maven-plugin](https://github.com/SonarSource/sonar-scanner-maven) from 5.0.0.4389 to 5.1.0.4751.
- [Release notes](https://github.com/SonarSource/sonar-scanner-maven/releases)
- [Commits](SonarSource/sonar-scanner-maven@5.0.0.4389...5.1.0.4751)

---
updated-dependencies:
- dependency-name: org.sonarsource.scanner.maven:sonar-maven-plugin
  dependency-version: 5.1.0.4751
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* Persian Translation: Add persian translation to abstract-document

* Persian Translation: Add abstract-document.png to abstract-document folder

* Persian Translation: Add codes to README.md of abstract-document

* Persian Translation: some improvements in abstract-document

* Persian Translation: Add refrence links in abstract-document

* Persian Translation: add rtl tag in abstract-document

* active-object : translate

* active-object: improve when to use

* active-object: improve when to use

* active-object: improve bullets (test)

* active-object: improve bullets (test)

* active-object: improve bullets (test)

* active-object: improve bullets (test)

* active-object: improve bullets

* active-object: Fix all bullets

* -added persian translation of factory pattern

* -renamed file

* -changed wikipedia definition

* -fixed table problem

* -fixed problems in bullet alignments

* Update README.md

-fixed alignment in bullets

* Update README.md

-changed tags to English

---------

Co-authored-by: Seyyed Keivan Shirkoubian <[email protected]>
import java.util.concurrent.atomic.AtomicInteger;

public class ActorSystem {
private final ExecutorService executor = Executors.newCachedThreadPool();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚡ Performance Issue

Unbounded thread pool can cause resource exhaustion.

Using an unbounded cached thread pool can lead to resource exhaustion under high load as new threads are continuously created without limits.

Current Code (Diff):

-   private final ExecutorService executor = Executors.newCachedThreadPool();
+   private final ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 2);
📝 Committable suggestion

‼️ IMPORTANT
Trust, but verify! 🕵️ Please review this suggestion with the care of a code archaeologist - check that it perfectly replaces the highlighted code, preserves all lines, maintains proper indentation, and won't break anything in production. Your future self will thank you! 🚀

Suggested change
private final ExecutorService executor = Executors.newCachedThreadPool();
private final ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 2);

String actorId = "actor-" + idCounter.incrementAndGet(); // Generate a new and unique ID
actor.setActorId(actorId); // assign the actor it's ID
actorRegister.put(actorId, actor); // Register and save the actor with it's ID
executor.submit(actor); // Run the actor in a thread
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐛 Correctness Issue

No exception handling for actor execution.

If an actor throws an uncaught exception, it will silently terminate without any notification, potentially causing system instability.

Current Code (Diff):

-     executor.submit(actor); // Run the actor in a thread
+     executor.submit(() -> {
+       try {
+         actor.run();
+       } catch (Exception e) {
+         // Log the exception or implement a supervision strategy
+         System.err.println("Actor " + actor.getActorId() + " failed with exception: " + e.getMessage());
+       }
+     }); // Run the actor in a thread with exception handling
📝 Committable suggestion

‼️ IMPORTANT
Trust, but verify! 🕵️ Please review this suggestion with the care of a code archaeologist - check that it perfectly replaces the highlighted code, preserves all lines, maintains proper indentation, and won't break anything in production. Your future self will thank you! 🚀

Suggested change
executor.submit(actor); // Run the actor in a thread
executor.submit(() -> {
try {
actor.run();
} catch (Exception e) {
// Log the exception or implement a supervision strategy
System.err.println("Actor " + actor.getActorId() + " failed with exception: " + e.getMessage());
}
});

}

public void shutdown() {
executor.shutdownNow(); // Stop all threads
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐛 Correctness Issue

Abrupt thread termination can cause resource leaks.

Using shutdownNow() immediately terminates all threads without allowing them to complete their work, potentially causing resource leaks or data corruption.

Current Code (Diff):

-     executor.shutdownNow(); // Stop all threads
+     executor.shutdown();
+     try {
+       if (!executor.awaitTermination(30, TimeUnit.SECONDS)) {
+         executor.shutdownNow();
+       }
+     } catch (InterruptedException e) {
+       executor.shutdownNow();
+       Thread.currentThread().interrupt();
+     } // Graceful shutdown with timeout
📝 Committable suggestion

‼️ IMPORTANT
Trust, but verify! 🕵️ Please review this suggestion with the care of a code archaeologist - check that it perfectly replaces the highlighted code, preserves all lines, maintains proper indentation, and won't break anything in production. Your future self will thank you! 🚀

Suggested change
executor.shutdownNow(); // Stop all threads
executor.shutdown();
try {
if (!executor.awaitTermination(30, TimeUnit.SECONDS)) {
executor.shutdownNow();
}
} catch (InterruptedException e) {
executor.shutdownNow();
Thread.currentThread().interrupt();
}

🔄 Dependencies Affected

src/main/java/com/iluwatar/actormodel/ActorSystem.java

Function: ActorSystem

Issue: Missing import for TimeUnit

Suggestion: Add import java.util.concurrent.TimeUnit;

Current Code (Diff):

+ import java.util.concurrent.TimeUnit;

* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.iluwatar.table.inheritance; /*
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐛 Correctness Issue

Malformed package declaration.

The package declaration is incorrectly followed by a multi-line comment which will cause compilation errors.

Current Code (Diff):

- package com.iluwatar.table.inheritance; /*
+ package com.iluwatar.table.inheritance;
+ /*
📝 Committable suggestion

‼️ IMPORTANT
Trust, but verify! 🕵️ Please review this suggestion with the care of a code archaeologist - check that it perfectly replaces the highlighted code, preserves all lines, maintains proper indentation, and won't break anything in production. Your future self will thank you! 🚀

Suggested change
package com.iluwatar.table.inheritance; /*
package com.iluwatar.table.inheritance;

* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.iluwatar.table.inheritance; /*
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐛 Correctness Issue

Malformed package declaration with embedded comment.

The package declaration has an embedded multi-line comment which will cause compilation failure as Java requires package declarations to be standalone statements.

Current Code (Diff):

- package com.iluwatar.table.inheritance; /*
+ package com.iluwatar.table.inheritance;
📝 Committable suggestion

‼️ IMPORTANT
Trust, but verify! 🕵️ Please review this suggestion with the care of a code archaeologist - check that it perfectly replaces the highlighted code, preserves all lines, maintains proper indentation, and won't break anything in production. Your future self will thank you! 🚀

Suggested change
package com.iluwatar.table.inheritance; /*
package com.iluwatar.table.inheritance;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants